package com.example.park_2306

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.base.mvi.BaseViewActivity
import com.example.park_2306.databinding.ActivityWelcomeBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class WelcomeActivity : BaseViewActivity<ActivityWelcomeBinding>() {
    override fun getLayout(): Int  = R.layout.activity_welcome

    override fun initView() {

        //比较时间  是否为7天内  7天内免广告
        val long = SPUtils.getInstance().getLong("time")
        if(System.currentTimeMillis()-long<7*24*60*60*1000){
          //7天内
            //权限控制
            start()
            finish()
        }else{
            lifecycleScope.launch {
                for (i in 5 downTo 1){
                    binding.djs.text = "${i}秒|跳过"
                    delay(1000)
                }
                start()
                finish()
            }
        }

        //点击跳过
        binding.djs.setOnClickListener {
            //权限控制
           start()
            finish()
        }
    }

    fun start(){
        if(SPUtils.getInstance().getInt("role")==20){
            ARouter.getInstance().build("/app/MainActivity").navigation(this,object :NavigationCallback{
                override fun onFound(postcard: Postcard?) {
                    //找到路径了
                }

                override fun onLost(postcard: Postcard?) {
                    //丢失
                }

                override fun onArrival(postcard: Postcard?) {
                    //到达
                }

                override fun onInterrupt(postcard: Postcard?) {
                    //拦截
                }
            })
        }else{
            ARouter.getInstance().build("/app/WebViewActivity").navigation()
        }
    }

}